package com.aop.SpElAop.LogAop.Test;

import com.aop.SpElAop.LogAop.Logging;
import org.springframework.stereotype.Service;

/**
 * @Package: com.aop.SpElAop.LogAop
 * @ClassName: MainTest
 * @Author: wulongkai
 * @CreateTime: 2024/7/9 11:08
 * @Description:
 */

@Service
public class LogTestService {

    @Logging(successMsg = "方法：#{#root.methodName}，参数：#{#p0}，返回值：#{#result}")
//    @Logging(successMsg = "方法：#{#root.method.name}，参数：#{#p0}，返回值：#{#result}")
    public String test1(String str) {
        return str + "test1";
    }

    @Logging(successMsg = "方法：#{#root.methodName}，参数：#{#p0}，返回值：#{#result}"
            , failMsg = "错误原因：#{#errorMsg}")
    public void test2() {
        throw new RuntimeException("系统异常");
    }

    @Logging(successMsg = "方法：#{#root.methodName}，参数：我的名字是#{#person.name}，今年#{#person.age}，返回值：#{#result}")
    public String test3(Person person) {
        return person.getName() + "-" + person.getAge();
    }


    @Logging(successMsg = "方法：#{#root.methodName}，参数：基础信息是#{#person.baseInfo.schoolName}，内部类：#{#person.listInfo[0].InnerListName}，返回值：#{#result}")
    public String test4(Person person) {
        return person.getName() + "-" + person.getAge();
    }

    @Logging(successMsg = "方法：#{#root.methodName}，参数：我的名字是#{#person.name}，今年#{#person.age}，返回值：#{#result}",
            condition = "#{#person.age > 24}")
    public String test5(Person person) {
        return person.getName() + "-" + person.getAge();
    }
}
